package org.me.app.instructor;

import org.me.app.R;
import org.me.app.R.id;
import org.me.app.R.layout;
import org.me.bean.Instructor;
import org.me.services.WSlib;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.net.Uri;

public class PostAnnouncementActivity extends Activity{
	
	
	private TextView tv_instructorName ;
	
	private EditText et_title;
	private EditText et_content;
	
	private Button btn_post;
	private Button btn_clear;
	private Button btn_quit;
	
	Instructor inst = new Instructor();
	String courseScheduleId = new String();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.postannouncement);
		
		Bundle b = getIntent().getExtras();
		inst = b.getParcelable("Instructor");
		courseScheduleId = b.getString("CourseScheduleId");
		
		et_title = (EditText)findViewById(R.id.et_title);
		et_content = (EditText)findViewById(R.id.et_content);
		
		tv_instructorName = (TextView)findViewById(R.id.tv_instructorname);
		tv_instructorName.setText("");
		
		btn_post = (Button)findViewById(R.id.btn_postann);
		btn_post.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
			
			String title = et_title.getText().toString();
			String content = et_content.getText().toString();
			
			WSlib ws = new WSlib();
			
			String result = ws.postAnnouncement(title, content, inst.getInstructorId(), courseScheduleId);
			
			Intent in = new Intent();
			in.setData(Uri.parse(result));
			setResult(RESULT_OK, in);
			finish();
			
			}
		});
		
		btn_clear = (Button)findViewById(R.id.btn_clear);
		btn_clear.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
			et_title.setText("");
			et_content.setText("");
			
			}
		});
		btn_quit = (Button)findViewById(R.id.btn_quit);
		btn_quit.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				Intent in = new Intent();
				in.setData(Uri.parse(""));
				setResult(RESULT_CANCELED, in);
				finish();
				
			}
		});
		
	}
	

}
